package com.xuecheng.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuecheng.common.domain.code.CommonErrorCode;
import com.xuecheng.common.exception.ExceptionCast;
import com.xuecheng.content.entity.TeachplanMedia;
import com.xuecheng.content.mapper.TeachplanMediaMapper;
import com.xuecheng.content.service.TeachplanMediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author itcast
 */
@Slf4j
@Service
public class TeachplanMediaServiceImpl extends ServiceImpl<TeachplanMediaMapper, TeachplanMedia> implements TeachplanMediaService {

    /**
     * @param
     * @return com.xuecheng.api.content.model.TeachplanMediaDTO
     * @Description //获取媒资信息与课程机构绑定情况
     * @Date 2021/12/15 15:51
     * @Param [mediaId] 媒资id-->只要有其相关数据则不能被删
     * 业务分析
     * 关键数据-->其内媒资id不能为空
     * 业务数据-->其有关于媒资的数据都不能删除
     */
    @Override
    public boolean teachplanMediaDTO(Long mediaId) {
        if (ObjectUtils.isEmpty(mediaId)) {
            ExceptionCast.cast(CommonErrorCode.E_100101);
        }
        LambdaQueryWrapper<TeachplanMedia> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TeachplanMedia ::getMediaId,mediaId );
        List<TeachplanMedia> list = this.list(queryWrapper);
        boolean result = true;
        //如果查出来有值则不能删除--
        if (list.size() > 0){
            result=false;
        }
        return result;
    }
}
